package com.ss.android.article.base.feature.detail2.a.c;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.detail.model.MixedAdsData;
import com.ss.android.article.base.feature.detail.model.PhoneAdsData;
import com.ss.android.article.base.feature.detail2.a.b.a;
import com.ss.android.article.base.feature.detail2.widget.ProgressTextView;
import com.ss.android.article.base.feature.detail2.widget.ProgressTextView.Status;
import com.ss.android.article.base.feature.detail2.widget.a.BaseDetailLayout;
import com.ss.android.article.base.feature.model.DownloadAppAd;
import com.ss.android.article.base.ui.EllipsisTextView;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.b.a.BaseAdsData;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.Image;

import org.json.JSONException;
import org.json.JSONObject;

public final class DetailAdLargePicLayout extends BaseDetailLayout implements z {
    ProgressTextView a;
    a b;
    long c;
    String d;
    JSONObject e;
    private View f;
    private NightModeAsyncImageView g;
    private TextView h;
    private EllipsisTextView j;
    private TextView k;
    private int l;
    private int m;
    private com.ss.android.article.base.feature.detail2.a.aa n;
    private ViewGroup o;
    private TextView p;
    private TextView q;

    public DetailAdLargePicLayout(Context arg1) {
        super(arg1);
    }

    public DetailAdLargePicLayout(Context arg2, byte arg3) {
        super(arg2, (byte) 0);
    }

    private void a(int arg3, int arg4) {
        ViewGroup.LayoutParams v0 = this.g.getLayoutParams();
        if (v0 != null) {
            if (arg3 > 0) {
                v0.width = arg3;
            }

            if (arg4 > 0) {
                v0.height = arg4;
            }

            this.g.setLayoutParams(v0);
        }
    }

    public final void initView() {
        super.initView();
        if (this.i == 0) {
            this.setBackgroundResource(com.ss.android.article.browser.R.drawable.detail_ad_bg);
        } else if (this.i == 1) {
            this.setBackgroundResource(com.ss.android.article.browser.R.color.transparent);
        }

        this.g = this.findViewById(com.ss.android.article.browser.R.id.ad_pic);
        this.h = this.findViewById(com.ss.android.article.browser.R.id.ad_source_tv_name);
        this.j = this.findViewById(com.ss.android.article.browser.R.id.ad_tv_title);
        this.a = this.findViewById(com.ss.android.article.browser.R.id.ad_tv_creative);
        this.k = this.findViewById(com.ss.android.article.browser.R.id.ad_label_info);
        this.f = this.findViewById(com.ss.android.article.browser.R.id.download_area);
    }

    public final void a(BaseAdsData arg6) {
        final BaseAdsData v0_1;
        if (arg6 != null) {
            this.c = arg6.id;
            try {
                this.e = new JSONObject();
                this.e.put("log_extra", arg6.logExtra);
            } catch (JSONException v0) {
                v0.printStackTrace();
            }

            this.d = arg6.pkg;
            this.n = new com.ss.android.article.base.feature.detail2.a.aa(arg6);
            if ((arg6 instanceof DownloadAppAd)) {
                v0_1 = arg6;
                this.b = new a(this.getContext(), ((DownloadAppAd) v0_1));
                this.a.setVisibility(VISIBLE);
                this.j.setText(((DownloadAppAd) v0_1).appAdTitle);
                if (!android.support.design.a.isTextEmpty(((DownloadAppAd) v0_1).appAdSourceLabel)) {
                    this.k.setText(((DownloadAppAd) v0_1).appAdSourceLabel);
                }

                ProgressTextView v2 = this.a;
                String v1 = android.support.design.a.isTextEmpty(((DownloadAppAd) v0_1).btnTxt) ? this.getResources().getString(com.ss.android.article.browser.R.string.j2) : ((DownloadAppAd) v0_1).btnTxt;
                v2.setText(((CharSequence) v1));
                this.a.setOnClickListener(new View.OnClickListener() {

                    public final void onClick(View arg2) {
                        if (DetailAdLargePicLayout.this.b != null) {
                            DetailAdLargePicLayout.this.b.c();
                        }
                    }
                });
                this.h.setText(v0_1.appName);
                if (((DownloadAppAd) v0_1).imageInfo == null) {
                    this.setOnClickListener(new h(this, arg6));
                    return;
                }

                this.m = this.b(((DownloadAppAd) v0_1).imageInfo.mWidth, ((DownloadAppAd) v0_1).imageInfo.mHeight);
                this.a(this.l, this.m);
                this.setAdImage(android.support.design.a.imageInfo2Image(((DownloadAppAd) v0_1).imageInfo));
            } else {
                if ((arg6 instanceof MixedAdsData)) {
                    v0_1 = arg6;
                    if (this.i != 1) {
                        this.setOnClickListener(new h(this, arg6));
                        return;
                    }

                    if (((MixedAdsData) v0_1).d == null) {
                        this.setOnClickListener(new h(this, arg6));
                        return;
                    }

                    this.g.setUrl(((MixedAdsData) v0_1).d);
                    this.m = this.b(((MixedAdsData) v0_1).e, ((MixedAdsData) v0_1).f);
                    this.a(this.l, this.m);
                    this.f.setVisibility(GONE);
                    this.o = this.findViewById(com.ss.android.article.browser.R.id.video_mix_area);
                    this.o.setVisibility(VISIBLE);
                    this.p = this.findViewById(com.ss.android.article.browser.R.id.ad_label_info_mix);
                    this.q = this.findViewById(com.ss.android.article.browser.R.id.ad_source_tv_name_mix);
                    this.j.setText(((MixedAdsData) v0_1).title);
                    if (!android.support.design.a.isTextEmpty(((MixedAdsData) v0_1).h)) {
                        this.p.setText(((MixedAdsData) v0_1).h);
                    }

                    this.q.setText(((MixedAdsData) v0_1).i);
                    this.setOnClickListener(new h(this, arg6));
                    return;
                }

                if (!(arg6 instanceof PhoneAdsData)) {
                    this.setOnClickListener(new h(this, arg6));
                    return;
                }

                v0_1 = arg6;
                this.f.setVisibility(VISIBLE);
                if (!android.support.design.a.isTextEmpty(((PhoneAdsData) v0_1).h)) {
                    this.k.setText(((PhoneAdsData) v0_1).h);
                }

                this.m = this.b(((PhoneAdsData) v0_1).imageWidth, ((PhoneAdsData) v0_1).imageHeight);
                this.a(this.l, this.m);
                this.h.setText(((PhoneAdsData) v0_1).sourceName);
                this.j.setText(((PhoneAdsData) v0_1).title);
                this.g.setUrl(((PhoneAdsData) v0_1).image);
                if (!TextUtils.isEmpty(((PhoneAdsData) v0_1).phoneNumber) && !TextUtils.isEmpty(((PhoneAdsData) v0_1).buttonText)) {
                    this.a.setText(((PhoneAdsData) v0_1).buttonText);
                    this.a.setOnClickListener(new View.OnClickListener() {
                        PhoneAdsData a = (PhoneAdsData) v0_1;

                        public final void onClick(View arg11) {
                            MobAdClickCombiner.onAdEvent(DetailAdLargePicLayout.this.getContext(), "detail_call", "click_call", DetailAdLargePicLayout.this.c, 0, DetailAdLargePicLayout.this.e, 1);
                            MobAdClickCombiner.onAdEvent(DetailAdLargePicLayout.this.getContext(), "detail_call", "click", DetailAdLargePicLayout.this.c, 0, DetailAdLargePicLayout.this.e, 1);
                            ToolUtils.e(DetailAdLargePicLayout.this.getContext(), this.a.phoneNumber);
                        }
                    });
                    this.setOnClickListener(new h(this, arg6));
                    return;
                }

                this.a.setVisibility(GONE);
            }

            label_65:
            this.setOnClickListener(new h(this, arg6));
        }
    }

    public final void a(DownloadShortInfo arg5) {
        if (arg5 == null) {
            this.a.setStatus(Status.IDLE);
        } else {
            float v0 = (((float) arg5.d)) / (((float) arg5.c));
            switch (arg5.b) {
                case 1:
                case 2: {
                    this.a.setStatus(Status.DOWNLOADING);
                    this.a.setProgress(v0);
                    return;
                }
                case 4: {
                    this.a.setStatus(Status.PAUSING);
                    this.a.setProgress(v0);
                    return;
                }
                case 8: {
                    if (ToolUtils.isAppInstalled(this.getContext(), this.d)) {
                        this.a.setStatus(Status.FINISH_OPEN);
                        this.n.a("detail_download_ad");
                    } else {
                        this.a.setStatus(Status.FINISH_INSTALL);
                    }
                    return;
                }
                case 16: {
                    this.a.setStatus(Status.FAILURE);
                    return;
                }
            }
            Logger.d("DetailAdLargePicLayout", "download short info error!");
            return;
        }
    }

    public final void a(final DownloadShortInfo downloadShortInfo, final int arg11, final long arg12, final long arg14) {
        this.post(new Runnable() {

            public final void run() {
                float v0 = (((float) arg14)) / (((float) arg12));
                if (arg11 == 1) {
                    DetailAdLargePicLayout.this.a.setStatus(Status.DOWNLOADING);
                    DetailAdLargePicLayout.this.a.setProgress(v0);
                } else if (arg11 == 2) {
                    DetailAdLargePicLayout.this.a.setStatus(Status.PAUSING);
                    DetailAdLargePicLayout.this.a.setProgress(v0);
                } else if (arg11 != 3) {
                    Logger.d("DetailAdLargePicLayout", "download short info error!");
                } else if (downloadShortInfo.b == 16) {
                    DetailAdLargePicLayout.this.a.setStatus(Status.FAILURE);
                } else if (downloadShortInfo.b == 8) {
                    if (ToolUtils.isAppInstalled(DetailAdLargePicLayout.this.getContext(), DetailAdLargePicLayout.this.d)) {
                        DetailAdLargePicLayout.this.a.setStatus(Status.FINISH_OPEN);
                    } else {
                        DetailAdLargePicLayout.this.a.setStatus(Status.FINISH_INSTALL);
                    }
                }
            }
        });
    }

    public final void adaptNightMode(boolean arg5) {
        int v1 = R.color.update_comment_more_text_selector;
        Resources v2 = this.getResources();
        TextView v3 = this.h;
        int v0 = this.i == 0 ? R.color.ssxinzi1 : R.color.ssxinzi2;
        v3.setTextColor(v2.getColorStateList(v0));
        this.j.setTextColor(v2.getColorStateList(com.ss.android.article.browser.R.color.ssxinheihui3));
        v3 = this.k;
        v0 = this.i == 0 ? R.color.ssxinzi12 : v1;
        v3.setTextColor(v2.getColorStateList(v0));
        v0 = this.i == 0 ? R.drawable.detail_ad_bg : R.drawable.e;
        this.setBackgroundResource(v0);
        v0 = this.i == 0 ? R.drawable.aq : R.drawable.video_detail_download_area_bg;
        this.f.setBackgroundResource(v0);
        this.a.b();
        this.g.adaptNightMode(arg5);
        if (this.p != null) {
            this.p.setTextColor(v2.getColorStateList(v1));
        }

        if (this.q != null) {
            this.q.setTextColor(v2.getColorStateList(com.ss.android.article.browser.R.color.ssxinzi3));
        }
    }

    private int b(int arg3, int arg4) {
        int v0;
        if (arg3 == 0 || arg4 == 0) {
            v0 = 0;
        } else {
            this.l = this.getResources().getDisplayMetrics().widthPixels - (((int) this.getResources().getDimension(R.dimen.d6))) * 2;
            v0 = this.l * arg4 / arg3;
        }

        return v0;
    }

    public final void b() {
        if (this.b != null) {
            this.b.d();
        }
    }

    public final int getLayoutRes() {
        int v0 = this.i == 0 ? R.layout.new_detail_ad_large_pic : R.layout.detail_video_ad_large_pic;
        return v0;
    }

    protected final void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (this.b != null) {
            this.b.a(((z) this));
        }
    }

    protected final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.b != null) {
            this.b.a();
        }
    }

    public final void setAdImage(Image arg2) {
        this.g.setImage(arg2);
    }
}

